$(function(){
	 lay('#version').html('-v'+ laydate.v);
	    //时间选择器
	  var startTime =   laydate.render({
	      elem: '#startTime',
	      done: function(value, date){
	    	  endTime.config.min={    	    		
	      	    	year:date.year,
	      	    	month:date.month-1,//关键
	                  date:date.date,
	                  hours:date.hours,
	                  minutes:date.minutes,
	                  seconds:date.seconds
	      	    };
	      }
	    });
	    
	 var endTime =  laydate.render({
  	        elem: '#endTime',
  	        done: function(value, date){
  	        	startTime.config.max={
  	    	    		year:date.year,
  	        	    	month:date.month-1,//关键
  	                    date:date.date,
  	                    hours:date.hours,
  	                    minutes:date.minutes,
  	                    seconds:date.seconds
  	    	    }
  	        }
  	    });
	   
})
layui.use('table', function(){
  var table = layui.table;
   
   
  //监听工具条
  table.on('tool(demo)', function(obj){
    var da = obj.data;
    //删除
    if(obj.event === 'delete'){
      layer.confirm('确认删除吗?', function(index){
    	layer.close(index);
        obj.del();
        var url="../../listenProduction/deleteProduction.action";
  	 	var data={"prodId":da.prodId,"isva":2};
  	    $.post(url,data,function(mes){
  		  if(mes>0){
			layer.msg("删除成功");
  		  }
  	  },"json")
      });
    //修改
    } else if(obj.event === 'update'){
    	layer.open({
  		  type: 2, //设置为iframe
  		  area: ['100%', '100%'],
  		  content: ['productionPlan.html?prodId='+da.prodId+"&prodPermit="+da.prodPermit+"&manufactureType="+da.manufactureType+"&addOrUpdate=2"] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']  	
  	  }); 
    	 
    }else if(obj.event === 'detail'){
    	layer.open({
    		 title: "生产明细",
    		  type: 2, //设置为iframe
    		  area: ['90%', '70%'],
    		  offset: '5%'
    		  ,content: ['productionDetail.html?prodId='+da.prodId] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
    	  }); 
    }else if(obj.event === 'manufacture'){
    	layer.open({
    		 title: "制造",
    		  type: 2, //设置为iframe
    		  area: ['90%', '70%'],
    		  offset: '5%'
    		  ,content: ['../manufacture/manufacture.html?prodId='+da.prodId] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
    	  }); 
    }else if(obj.event === 'quality'){
    	layer.confirm('确认提交质检吗?', function(index){
		var index = layer.load(0, {
		  shade: [0.1,'#fff'] //0.1透明度的白色背景
		});
    	var pdNumber=0;
    	$.ajaxSetup({
			async: false
		});
    	var url="../../listenProductionDetail/findProductionDetail.action";
    	var data={"prodId":da.prodId};
	  	  $.post(url,data,function(mes){
	  		   $.each(mes.data,function(i,item){
	  			 pdNumber=parseInt(pdNumber)+parseInt(item.pdNumber)
	  		   })
	  	  },"json")
	  	  $.ajaxSetup({
			async: true
		});
    	 console.info(pdNumber)
    	
    	var submitString=da.prodId+","+pdNumber+","+2;
    	var url="../../listenQualityTesting/addQualityTesting.action";
    	var data={"submitString":submitString};
	  	  $.post(url,data,function(mes){
	  		   if(mes>0){
	  			 layer.close(index);
	  			 layer.msg("提交质检成功")
	  			 location.reload();
	  		   }
	  	  },"json")
    	});
    }else if(obj.event === 'auditing'){
    	layer.confirm('确认提交审核吗?', function(index){
		var index = layer.load(0, {
			  shade: [0.1,'#fff'] //0.1透明度的白色背景
			});
    	var url="../../listenProduction/update.action";
    	var data={"prodId":da.prodId,"prodPermit":1};
	  	  $.post(url,data,function(mes){
	  		   if(mes>0){
	  			 layer.close(index);
	  			 layer.msg("提交审核成功")
	  			 location.reload();
	  		   }
	  	  },"json")
    	});
   }
    
    
  });
   
  
  //表单重载
  var $ = layui.$, active = {
		    reload: function(){
		      var prodPermit = $('#prodPermit');
		      var manufactureType = $('#manufactureType');
		      var startTime = $('#startTime');
		      var endTime = $('#endTime');
		      //执行重载    查询
		      table.reload('idTest', {
		        page: {
		          curr: 1 //重新从第 1 页开始
		        }
		        ,where: {
		        	prodPermit: prodPermit.val(),
		        	manufactureType: manufactureType.val(),
		        	prodStartTime: startTime.val(),
		        	prodEndTime: endTime.val()
		        }
		      });
		    }
		  };
  
  $('#productionSreach').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });
  
 
 
  
  /**
  * 增加
  */
  $('#insert').on('click', function(){
	  layer.open({
		  type: 2, //设置为iframe
		  area: ['100%', '74%'],
		  offset: '5%',
		  content: ['productionPlan.html?addOrUpdate=1'] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
		  
	  	   
	  }); 
	          
  });
});

 